<%@page contentType="text/html;charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>班级信息管理</title>
        <meta http-equiv="content-type"
        content="text/html" charset="UTF-8"/>
        <link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.3/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.3/themes/icon.css">
    <script type="text/javascript" src="jquery-easyui-1.3.3/jquery.min.js"></script>
    <script type="text/javascript" src="jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
    	var url;
    
        function searchGrade(){
    		$('#dg').datagrid('load',{
    			gradeName:$('#s_gradeName').val()
    		});
    	}
        
        function gradeDelete(){
        	var selectRows = $("#dg").datagrid("getSelections");
         	if(selectRows.length==0){
         		$.messager.alert("系统提示","请选择要删除的数据！");
         		return;
         	}
         	var strIds = [];
         	for(var i=0;i<selectRows.length;i++){
         		strIds.push(selectRows[i].id);
         	}
         	var ids = strIds.join(",");
         	$.messager.confirm("系统提示","你确定要删除这<font color='red'>"+selectRows.length+"</font>条数据吗？",function(r){
         		if(r){
         			$.post("gradeDelete",{delIds:ids},function(result){
         				if(result.success){
         					$.messager.alert("系统提示","您已成功删除<font color='red'>"+result.delNums+"</font>条数据！")
         					$("#dg").datagrid("reload");
         				}else{
         					$.messager.alert("系统提示","<font color='red'>"+selectRows[result.errorIndex].gradeName+"</font>"+ result.errorMsg);
         				}
         			},"json");
         		}
         	});
        }
        
        function openGradeAddDialog(){
        	$("#dig").dialog("open").dialog("setTitle","添加班级信息");
        	url="gradeSave";
        }
        
        function closeGradeDialog(){
        	$("#dig").dialog("close");
        	resetValue();
        }
        
        function resetValue(){
        	$("#gradeName").val("");
        	$("#gradeDesc").val("");
        }
        
        function gradeSave(){
        	$("#fm").form("submit",{
        		url:url,
        		onsubmit:function(){
        			return $(this).form("validate");
        		},
        		success:function(result){
        			if(result.errorMsg){
        				$.messager.alert("系统提示",result.errorMsg);
        				return;
        			}else{
        				$.messager.alert("系统提示","保存成功！")
        				resetValue();
        				$("#dig").dialog("close");
        				$("#dig").datagrid("reload");
        			}
        		}
        	});
        }
        
        function openGradeEditDialog(){
        	var selectRows = $("#dg").datagrid("getSelections");
        	if(selectRows.length!=1){
        		$.messager.alert("系统提示","请选择一条修改的数据！");
        		return;
        	}
        	var row = selectRows[0];
        	$("#dig").dialog("open").dialog("setTitle","编辑班级信息");
        	$("#fm").form("load",row);
        	url = "gradeSave?id="+row.id
        }
    </script>
    </head>
    <body style="margin:5px;">
    	<table id="dg" title="班级信息" class="easyui-datagrid" fitColumns="true"
         pagination="true" rownumbers="true" url="gradeList" fit="true" toolbar="#tb">
            <thead>
                <tr>
                    <th field="cb" checkbox="true"></th>
                    <th field="id" width="50">编号</th>
                    <th field="gradeName" width="100">班级名称</th>
                    <th field="gradeDesc" width="200">班级描述</th>
                </tr>
            </thead>
        </table>
        
        <div id="tb">
            <div>
                <a href="javascript:openGradeAddDialog();" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
                <a href="javascript:openGradeEditDialog();" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
                <a href="javascript:gradeDelete();" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
            </div>
            <div>&nbsp;班级名称：<input type="text" name="s_gradeName" id="s_gradeName">
            <a href="javascript:searchGrade()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a></div>
        </div>
        
        <div id="dig" class="easyui-dialog" style="width:400px;height:280px; padding:10px;"
         closed="true" buttons="#dig-button">
            <form id="fm" method="post">
            <table>
                <tr>
                    <td>班级名称</td>
                    <td><input type="text" name="gradeName" id="gradeName" class="easyui-validatebox" required="true"></td>
                </tr>
                <tr>
                    <td valign="top">班级描述</td>
                    <td><textarea rows="7" cols="30" name="gradeDesc" id="gradeDesc"></textarea></td>
                </tr>
                </table>
            </form>
            <div id="dig-button">
                <a href="javascript:gradeSave();" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
                <a href="javascript:closeGradeDialog();" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
            </div>
        </div>
    </body>
</html>